﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;

namespace SmartMathLibrary.Storage
{
    /// <summary>
    /// This class represents a kind of storage, which is optimized for a maximum of performance.
    /// Be careful what you add to the storage, there will be no check of point values.
    /// </summary>
    [Serializable]
    public class HighPerformancePointStorage : AbstractPointStorage, SmartMathLibrary.Storage.IPointStorage
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="HighPerformancePointStorage"/> class.
        /// </summary>
        /// <param name="size">The size of the storage.</param>
        public HighPerformancePointStorage(int size)
            : base(size)
        {
        }

        /// <summary>
        /// This method adds a new point to the current storage. If the maximum capacity of the
        /// storage is exceeded, it will automatically overwrite the smallest point of the storage.
        /// </summary>
        /// <param name="item">The point item, which should be added.</param>
        public void AddPoint(StoragePoint item)
        {
            this.positionData[cachePointer] = item;
            this.cachePointer = (this.cachePointer + 1) % this.cacheSize;

            if (this.fillSize < this.cacheSize)
            {
                this.fillSize++;
            }
        }
    }
}